import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.*;

/**
 * 
 */

/**
 * @author salim
 *
 */
public class InterfaceGen {

	private static String interfaceName;
	private static final String interfacePath = "../src/";
	private static PrintWriter pw;
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		if (args.length != 1) {
            System.err.println("Usage: java InterfaceGen <name>");
            return;
        }

        String className = args[0];
        interfaceName = className + "_itf";        
        
        Class classe;
        
        try {
            classe = Class.forName(className);
        } catch (ClassNotFoundException e) {
            System.err.println ("Class "+className+" not found.");
            return;
        }
        
        // instantiate a file writer
        try {
			pw = new PrintWriter(interfacePath + interfaceName + ".java");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
        // begin class definition
		pw.println("public interface " + interfaceName + " extends SharedObject_itf {");	
		
        // write methods signature
		Method[] methodes = classe.getDeclaredMethods();

		for (int i = 0; i < methodes.length; i++) {
			Method meth = methodes[i];
			
			String protection = Modifier.toString(meth.getModifiers());
			
			String returnTypeName = meth.getReturnType().getName();
			
			String methodName = meth.getName();
			
			String signature = "\t" + protection +" "+ returnTypeName + " " + methodName+ "(";

			
			Class[] params = meth.getParameterTypes();
			
			int paramsLength = params.length;
			
			if (paramsLength > 0) {
				
				signature += params[0].getName() + " id" + 0;
			
				for (int j = 1; j < paramsLength; j++) {
					signature += ", " + params[j].getName() + " id" + j;
				}
				
			}
			
			signature += ");";
			
			pw.println(signature);
		}

		// end class definition
		pw.println("}");
		pw.close();
		
	}

}
